package org.demo.base.dao;

import java.util.List;

import javax.sql.DataSource;

import org.demo.domain.person.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class PersonDAOImpl implements PersonDAO {

	/* ---- Instance Variables ---- */
	@Autowired
	private DataSource dataSource = null;
	@Autowired
	private JdbcTemplate jdbcTemplate = null;
	@Autowired
	private PersonRowMapper personRowMapper = null;


	@Override
	public List<Person> findAll() {
		String sql = "select * from demo.Person";
		return jdbcTemplate.query(sql, new PersonRowMapper());
	}

	@Override
	public Person get(Integer id) {
		String sql = "select * from demo.Person where id = ?";
		return jdbcTemplate.queryForObject(sql, new Object[]{id}, personRowMapper);
	}



	public DataSource getDataSource() {
		return dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

}
